// <!-- 轮播图 -->

window.onload = function() {
    var box = this.document.getElementsByClassName("re")[0];
    var lik = box.getElementsByTagName("li");

    function fun(i, j) { //转换图片函数，就是把透明度改了一下
        lik[i].style.opacity = 1;
        lik[j].style.opacity = 0;
        lik[i + 3].style.backgroundColor = "pink"; //改一下小图标
        lik[j + 3].style.backgroundColor = "#00000000"
    }
    fun(0, 1); //初始化下
    var i = 0;

    function auto() { //轮播循环函数
        if (++i >= 3) {
            i = 0;
            fun(0, 2);
        } else fun(i, i - 1);
    }
    timer = this.setInterval(auto, 3000);
    box.onmouseover = function() { //鼠标划上去，停止轮播
        console.log('good');
        clearInterval(timer);
    }
    box.onmouseout = function() { //鼠标划出，继续轮播
        timer = setInterval(auto, 3000); //调用定时器
    }
    var j = 0;
    for (; j < 3; j++) { //点击小图标也可以转换图片
        lik[j + 3].ind = j;
        lik[j + 3].onclick = function() {
            fun(this.ind, i)
            i = this.ind;
        }
    }

}